package com.healthyeating.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.healthyeating.common.annotation.Log;
import com.healthyeating.common.core.controller.BaseController;
import com.healthyeating.common.core.domain.AjaxResult;
import com.healthyeating.common.enums.BusinessType;
import com.healthyeating.manage.domain.FoodType;
import com.healthyeating.manage.service.IFoodTypeService;
import com.healthyeating.common.utils.poi.ExcelUtil;

/**
 * 食材类型Controller
 * 
 * @author 段奇乐
 * @date 2024-12-02
 */
@RestController
@RequestMapping("/manage/foodType")
public class FoodTypeController extends BaseController
{
    @Autowired
    private IFoodTypeService foodTypeService;

    /**
     * 查询食材类型列表
     */
    @PreAuthorize("@ss.hasPermi('manage:foodType:list')")
    @GetMapping("/list")
    public AjaxResult list(FoodType foodType)
    {
        List<FoodType> list = foodTypeService.selectFoodTypeList(foodType);
        return success(list);
    }

    /**
     * 导出食材类型列表
     */
    @PreAuthorize("@ss.hasPermi('manage:foodType:export')")
    @Log(title = "食材类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FoodType foodType)
    {
        List<FoodType> list = foodTypeService.selectFoodTypeList(foodType);
        ExcelUtil<FoodType> util = new ExcelUtil<FoodType>(FoodType.class);
        util.exportExcel(response, list, "食材类型数据");
    }

    /**
     * 获取食材类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:foodType:query')")
    @GetMapping(value = "/{foodTypeId}")
    public AjaxResult getInfo(@PathVariable("foodTypeId") Long foodTypeId)
    {
        return success(foodTypeService.selectFoodTypeByFoodTypeId(foodTypeId));
    }

    /**
     * 新增食材类型
     */
    @PreAuthorize("@ss.hasPermi('manage:foodType:add')")
    @Log(title = "食材类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FoodType foodType)
    {
        return toAjax(foodTypeService.insertFoodType(foodType));
    }

    /**
     * 修改食材类型
     */
    @PreAuthorize("@ss.hasPermi('manage:foodType:edit')")
    @Log(title = "食材类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FoodType foodType)
    {
        return toAjax(foodTypeService.updateFoodType(foodType));
    }

    /**
     * 删除食材类型
     */
    @PreAuthorize("@ss.hasPermi('manage:foodType:remove')")
    @Log(title = "食材类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{foodTypeIds}")
    public AjaxResult remove(@PathVariable Long[] foodTypeIds)
    {
        return toAjax(foodTypeService.deleteFoodTypeByFoodTypeIds(foodTypeIds));
    }
}
